<template>
  <div class="app">
    <div class="header">
      <div class="go-back" @click="goBack">
        <span class="arrow"></span>
        <span class="arrow green"></span>
      </div>
      <h1>Alibaba外卖网</h1>
      <div class="login">登录</div>
    </div>

    <div class="search" v-show="$route.fullPath.indexOf('/detail/') < 0">
      <input type="text" v-model="msg" @keyup.enter="showSearch" placeholder="搜索商品名称">
    </div>
    <router-view/>
    {{$store.state.search}}
  </div>
</template>

<style lang="scss">
@import "./base.scss";
* {
  margin: 0;
  padding: 0;
  list-style: none;
}
html,
body {
  background: #efefef;
}
.app {
  .header {
    background: $navColor;
    color: #fff;
    display: flex;
    line-height: 60px;
    height: 60px;
    h1 {
      flex: 1;
      font-size: 20px;
      font-weight: normal;
      text-align: center;
    }
    .login,
    .go-back {
      width: 60px;
      text-align: center;
    }
    .go-back {
      position: relative;
    }
    .arrow {
      position: absolute;
      top: 21px;
      left: 9px;
      @include arrow(9px, #fff, right);
      &.green {
        border-right-color: $navColor;
        left: 11px;
      }
    }
    .login {
      font-size: 16px;
    }
  }
  .search {
    display: flex;
    padding: 10px 20px;
    background: #fff;

    input {
      display: block;
      flex: 1;
      // padding: 10px 20px;
      padding-left: 16px;
      outline: none;
      border: none;
      background: #efefef;
      border-radius: 17px;
      line-height: 30px;
    }
  }
}
</style>

<script>
export default {
  data() {
    return {
      msg: ""
    };
  },
  methods: {
    showSearch: function() {
      this.$store.commit("changeSearch", this.msg);
      this.msg = "";
    },
    goBack() {
      history.back(-1);
    }
  }
};
</script>
